import java.util.*;
public class MyStackDemo {
    public int elem[];
    public int usedSize;

    public MyStackDemo(){
        this.elem=new int[2];
    }

    public void push(int val){
        if(isFull()){
            this.elem=Arrays.copyOf(this.elem,2*this.elem.length);
        }
        this.elem[this.usedSize++]=val;
    }

    public int pop(){
        if(isEmpty()){
            throw new RuntimeException("当前栈为空");
        }
        int ret=this.elem[usedSize-1];
        this.usedSize--;
        return ret;
    }

    public int peek(){
        if(isEmpty()) {
            throw new RuntimeException("栈为空！");
        }
        return this.elem[this.usedSize-1];
    }

    public boolean isFull(){
        return this.usedSize==elem.length;
    }

    public boolean isEmpty(){
        return this.usedSize==0;
    }

    public int getUsedSize() {
        return usedSize;
    }
}
